package com.luocj.muke.demo.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v4.app.FragmentActivity;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.luocj.muke.demo.R;
import com.luocj.muke.demo.model.NewsModel;

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Handler;

public class NewsAdapter extends RecyclerView.Adapter<NewsAdapter.Holder> {
    private Context mContext;
    //    private ArrayList<String> datas = new ArrayList<>();
    private ArrayList<NewsModel.NewslistBean> mDatas = new ArrayList<>();

    public NewsAdapter(Context context, ArrayList<NewsModel.NewslistBean> data) {
        this.mContext = context;
        this.mDatas = data;

    }

    @NonNull
    @Override
    public Holder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(mContext).inflate(R.layout.item_news, parent, false);
        Holder holder = new Holder(inflate);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull Holder holder, int position) {
        holder.tvContent.setText(mDatas.get(position).getTitle() + position);
    }

    @Override
    public int getItemCount() {
        return mDatas.size();
    }

    //下拉刷新
    public void setNewdata(List<NewsModel.NewslistBean> data) {
        if (mDatas != null) {
            mDatas.clear();
            mDatas.addAll(data);
        }
        notifyDataSetChanged();
    }

    public void setLoadMore(ArrayList<NewsModel.NewslistBean> temp) {
        if (mDatas!=null){
            mDatas.addAll(temp);
        }
        notifyItemRangeChanged(mDatas.size(),temp.size());
    }


    public class Holder extends RecyclerView.ViewHolder {
        private TextView tvContent;

        public Holder(View itemView) {
            super(itemView);
            tvContent = itemView.findViewById(R.id.tv_news);
        }
    }

}
